# 传统信号处理Ａgent
from apps.fmcw.core.ira_observe import IraObserve
from apps.fmcw.core.ira_action import IraAction
from apps.fmcw.core.fmcw_rsp import FmcwRsp as RSP

class TspAgent(object):
    def __init__(self):
        self.name = 'apps.fmcw.core.tsp_agent.TspAgent'

    def notify(self, obs:IraObserve) -> IraAction:
        action = IraAction(n=3)
        action.dt_action[0] = 1
        print(f'########################################################################')
        #　雷达信号处理－距离多普勒
        RDMs = RSP.range_doppler(obs.RDC)
        RSP.draw_range_doppler()
        # 雷达信号处理－CA-CFAR
        RDM_mask, cfar_ranges, cfar_dopps, K = RSP.ca_cfar(RDMs)
        RSP.draw_ca_cfar(RDM_mask)
        # 雷达信号处理－MUSIC角度估计
        music_spectrum, a1 = RSP.music_angle(RDMs, cfar_ranges, cfar_dopps, K)
        RSP.draw_music_angle(music_spectrum, K)
        # 雷达信号处理－距离角度
        range_az_music = RSP.range_angle(obs.RDC, a1)
        RSP.draw_range_angle(range_az_music)
        # 雷达信号处理－生成点云
        coor1, coor2 = RSP.point_cloud(music_spectrum, cfar_ranges)
        RSP.draw_point_cloud(coor1, coor2)

        return action